<?php namespace Home\Controller;
use Hdphp\Controller\Controller;
//列表页面控制器
class ListController extends Controller{
	public function index(){
		//先实例化模型
		$cateModel = new \Common\Model\Cate;
		$tagModel = new \Common\Model\Tag;
		$arcModel = new \Common\Model\Arc;
		$arcTagModel = new \Common\Model\ArcTag;
		//判断分类还是标签,如果是分类的话
		$cid = Q('get.cid',0,'intval');
			//1.名称
			$name = '分类';
			//2.值,pluck找到一个字段
			$value = $cateModel ->where("cid={$cid}")->pluck('cname');
			//3.文章总数
			//获得当前分类的所有的子级的cid
			$cids = $cateModel->getSon($cateModel->get(),$cid);
			//把自己也压进去
			$cids[]=$cid;
			//where条件要多次使用就给个值,然后直接用
			//implode把数组转化成字符串
			$where = "category_cid IN(" . implode(',',$cids) .")";
			//获得文章总数
			$total = $arcModel->where($where)->count();
			//4.所有文章
			//分类表和文章表连接
			$data = $arcModel->join('category','category_cid','=','cid')->field('aid,title,sendtime,author,cid,cname,digest,thumb')->where($where)->get();
			foreach($data as $k => $v){
				//中间表和标签关联
				$data[$k]['tag'] = $arcTagModel ->join('tag','tag_tid','=','tid')->where("article_aid={$v['aid']}")->get();		
				$cData=$cateModel->where(array('cid'=>$cid))->pluck('cname');
//				p($cData);die;
				View::with('cData',$cData);	
			}
		
		//分配变量
		View::with('name',$name);
		View::with('value',$value);
		View::with('total',$total);
		View::with('data',$data);
		
	    View::make();
		
	}
}

































 ?>